package it.polimi.TravelDream.web.beans;

import java.util.ArrayList;
import java.util.List;

import it.polimi.TravelDream.ejb.dtos.ExcursionDTO;
import it.polimi.TravelDream.ejb.dtos.FlightDTO;
import it.polimi.TravelDream.ejb.dtos.PackageDTO;
import it.polimi.TravelDream.ejb.dtos.RoomDTO;
import it.polimi.TravelDream.ejb.searchManager.BasicPackageMgr;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

@ManagedBean(name = "PackageMgr")
@SessionScoped
public class BasicPackageMgrBean {
	@EJB
	private BasicPackageMgr pkgMgr;
	private List <PackageDTO> currentList;
	private PackageDTO current;
	private boolean cityCheck;
	private boolean nameCheck;
	private boolean dateCheck;
	
	private List<FlightDTO> currentFlights;
	private List<RoomDTO> currentRooms;
	private List<ExcursionDTO> currentExcursions;
	
	
	public BasicPackageMgrBean(){
		this.currentList = new ArrayList<PackageDTO>();
		this.current = new PackageDTO();
		this.currentFlights = new ArrayList<FlightDTO>();
	}
	
	public String search(){
		if(cityCheck && !nameCheck && !dateCheck){
			pkgMgr.searchByCity();
		}
		else if(cityCheck && nameCheck && !dateCheck){
			pkgMgr.searchByNameAndCity();
		}
		else if(cityCheck && nameCheck && dateCheck){
			pkgMgr.searchByNameCityAndExpirationDate();
		}
		else if(cityCheck && !nameCheck && dateCheck){
			pkgMgr.searchByExpirationDateAndCity();
		}
		else if(!cityCheck && nameCheck && dateCheck){
			pkgMgr.searchByExpirationDateAndName();
		}
		else if(!cityCheck && !nameCheck && dateCheck){
			pkgMgr.searchByExpirationDate();
		}
		else if(!cityCheck && nameCheck && !dateCheck){
			pkgMgr.searchByName();
		}
		currentList = pkgMgr.getPackageResultList();
		return "search package results?faces-redirect=true";
	}
	
	public String goToDetailFlights(PackageDTO packageDTO) {
		currentFlights = packageDTO.getFlights();
		return "detail flights?faces-redirect=true";
	}
	
	public String goToDetailRooms(PackageDTO packageDTO) {
		currentRooms = packageDTO.getRooms();
		return "detail rooms?faces-redirect=true";
	}
	
	public String goToDetailExcursions(PackageDTO packageDTO) {
		currentExcursions = packageDTO.getExcursions();
		return "detail excursions?faces-redirect=true";
	}
	
	public String searchByTravelID(){
		pkgMgr.searchByTravelID();
		currentList = pkgMgr.getPackageResultList();
		return "search package results?faces-redirect=true";
	}
	
	public String goToAllTravels() {
		pkgMgr.searchAllAvailablePackage();
		currentList = pkgMgr.getPackageResultList();
		return "tutti i viaggi?faces-redirect=true";
	}
	
	
	public boolean isCityCheck() {
		return cityCheck;
	}

	public void setCityCheck(boolean cityCheck) {
		this.cityCheck = cityCheck;
	}

	public boolean isNameCheck() {
		return nameCheck;
	}

	public void setNameCheck(boolean nameCheck) {
		this.nameCheck = nameCheck;
	}

	public boolean isDateCheck() {
		return dateCheck;
	}

	public void setDateCheck(boolean dateCheck) {
		this.dateCheck = dateCheck;
	}

	public BasicPackageMgr getPkgMgr() {
		return pkgMgr;
	}

	public void setPkgMgr(BasicPackageMgr pkgMgr) {
		this.pkgMgr = pkgMgr;
	}

	public List<PackageDTO> getCurrentList() {
		return currentList;
	}

	public void setCurrentList(List<PackageDTO> currentList) {
		this.currentList = currentList;
	}

	public PackageDTO getCurrent() {
		return current;
	}

	public void setCurrent(PackageDTO current) {
		this.current = current;
	}

	public List<FlightDTO> getCurrentFlights() {
		return currentFlights;
	}

	public void setCurrentFlights(List<FlightDTO> currentFlights) {
		this.currentFlights = currentFlights;
	}

	public List<RoomDTO> getCurrentRooms() {
		return currentRooms;
	}

	public void setCurrentRooms(List<RoomDTO> currentRooms) {
		this.currentRooms = currentRooms;
	}

	public List<ExcursionDTO> getCurrentExcursions() {
		return currentExcursions;
	}

	public void setCurrentExcursion(List<ExcursionDTO> currentExcursions) {
		this.currentExcursions = currentExcursions;
	}
}
